﻿#region Usings

using KanbanBoard.Server.Command.DomainModel;
using KanbanBoard.Server.Command.Infrastructure;

#endregion

namespace KanbanBoard.Server.Command {
    public class TaskBoardCommandService : ITaskBoardCommandService {
        public void CreateTask(int taskBoardId) {
            CommandBus.Queue(context => {
                                 var taskBoard = context.Get<TaskBoard>(taskBoardId);

                                 taskBoard.CreateNewTask();
                             });
        }

        public void ChangeTaskDescription(int taskId, string description) {
            CommandBus.Queue(context => {
                                 var task = context.Get<Task>(taskId);

                                 task.ChangeDescription(description);
                             });
        }

        public void Pull(int taskId, int columnId) {
            CommandBus.Queue(context => {
                                 var task = context.Get<Task>(taskId);
                                 var column = context.Get<Column>(columnId);

                                 task.Move().To(column);
                             });
        }

        public void DeleteTask(int taskId) {
            CommandBus.Queue(context => {
                                 var task = context.Get<Task>(taskId);

                                 task.Delete();
                                 context.Delete(task);
                             });
        }

        public void PrioritizeAbove(int taskId, int lowerPriorityTaskId) {
            CommandBus.Queue(context => {
                                 var task = context.Get<Task>(taskId);
                                 var lowerPriorityTask = context.Get<Task>(lowerPriorityTaskId);

                                 task.Prioritize().Above(lowerPriorityTask);
                             });
        }

        public void PrioritizeBelow(int taskId, int higherPriorityTaskId) {
            CommandBus.Queue(context => {
                                 var task = context.Get<Task>(taskId);
                                 var higherPriorityTask = context.Get<Task>(higherPriorityTaskId);

                                 task.Prioritize().Below(higherPriorityTask);
                             });
        }
    }
}